﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using BCCommon.TMS.FreightEnums;
using BCCommon.TMS.Order;
using BCDto.CRM.BigCustomerFreightConfiguration;
using BCService.CRM.BigCustomerFreightConfiguration;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;

namespace BCTMSRESTful.Controllers.Management.CRM.BigCustomerFreightConfiguration
{


    /// <summary>
    /// 大客户运费配置接口
    /// </summary> 
    [ApiExplorerSettings(GroupName = "CRMAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class BigCustomerFreightConfigurationController : ManagementBaseController
    {
        #region var
        private IBigCustomerFreightConfigurationService bigCustomerFreightConfigurationService;
        #endregion


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public BigCustomerFreightConfigurationController(IBigCustomerFreightConfigurationService bigCustomerFreightConfigurationService)
        {
            this.bigCustomerFreightConfigurationService = bigCustomerFreightConfigurationService;
        }
        #endregion

        #region POST 添加  
        /// <summary>
        /// 添加新大客户运费配置纪录
        /// </summary>
        /// <param name="dto">大客户运费配置数据模型</param>
        /// <returns></returns>
        [Log("添加新大客户运费配置纪录")]
        [HttpPost]
        [ProducesResponseType(typeof(BigCustomerFreightConfigurationRequestDto), 200)]
        public IActionResult Post([FromBody] BigCustomerFreightConfigurationRequestDto dto)
        {
            var a = bigCustomerFreightConfigurationService.Add(dto, this.Admin);
            return Ok(a);
        }

        #endregion

        #region PUT 修改   
        /// <summary>
        /// 修改大客户运费配置纪录
        /// </summary>
        /// <param name="dto">大客户运费配置数据模型</param>
        /// <returns></returns>
        [Log("修改大客户运费配置纪录")]
        [HttpPut]
        [ProducesResponseType(typeof(BigCustomerFreightConfigurationPutDto), 200)]
        public IActionResult Put([FromBody] BigCustomerFreightConfigurationPutDto dto)
        {
            var a = Ok(bigCustomerFreightConfigurationService.Update(dto, this.Admin));
            return a;
        }
        #endregion

        #region 删除  
        /// <summary>
        /// 删除大客户运费配置纪录
        /// </summary>
        /// <param name="bigCustomerFreightConfigurationId">大客户运费配置ID</param>
        /// <returns></returns>
        [Log("删除大客户运费配置纪录")]
        [HttpDelete("{big_customer_freight_configuration_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "big_customer_freight_configuration_id")] long bigCustomerFreightConfigurationId)
        {
            bigCustomerFreightConfigurationService.Delete(bigCustomerFreightConfigurationId);
            return NoContent();
        }
        #endregion

        #region GetByID     
        /// <summary>
        /// 获取一条大客户运费配置纪录
        /// </summary>
        /// <param name="bigCustomerFreightConfigurationId">大客户运费配置ID</param>
        /// <returns></returns>
        [HttpGet("{big_customer_freight_configuration_id}")]
        [ProducesResponseType(typeof(BigCustomerFreightConfigurationDto), 200)]
        public IActionResult Get([FromRoute(Name = "big_customer_freight_configuration_id")] long bigCustomerFreightConfigurationId)
        {
            return (Ok(bigCustomerFreightConfigurationService.GetById(bigCustomerFreightConfigurationId)));

        }
        #endregion

        #region Query 查询大客户运费配置
        /// <summary>
        /// 查询大客户运费配置
        /// </summary>
        /// <param name="bigCustomerId">大客户Id</param>
        /// <param name="vehicleTypeId">车辆类型id</param>
        /// <param name="vehicleCategoryReferenceId">车辆型映射id</param>
        /// <param name="provinceCode">省编码</param>
        /// <param name="cityCode">市编码</param>
        /// <param name="countyCode">区/县编码</param>
        /// <param name="sourceType">订单来源</param>
        /// <param name="freightType">物流类型</param>
        /// <param name="pageIndex">起始页</param>
        /// <param name="pageSize">页数量</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<BigCustomerFreightConfigurationViewDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "big_customer_id")] long? bigCustomerId,
            [FromQuery(Name = "vehicle_type_id")] int? vehicleTypeId,
            [FromQuery(Name = "vehicle_category_reference_id")] int? vehicleCategoryReferenceId,
            [FromQuery(Name = "province_code")] string provinceCode,
            [FromQuery(Name = "community_code")] string cityCode,
            [FromQuery(Name = "county_code")] string countyCode,
            [FromQuery(Name = "source_type")] OrderSourceType? sourceType,
            [FromQuery(Name = "freight_type")] FreightType? freightType,
            [FromQuery(Name = "index")] int? pageIndex = 1, 
            [FromQuery(Name = "size")] int? pageSize = 10)
        {
            var a = Ok(bigCustomerFreightConfigurationService.GetList(this.Admin,bigCustomerId, vehicleTypeId, vehicleCategoryReferenceId, provinceCode, cityCode, countyCode, sourceType, freightType,pageIndex.Value, pageSize.Value));
            return a;
        }
        #endregion
    }

}
